import { GSprite } from "../../../../../com/mui/controls/GSprite";
import { CopyConfig } from "../../../resource/CopyConfig";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { CopyShortcutsItem } from "./CopyShortcutsItem";
import { Language } from "../../../../../extend/language/Language";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { DragEvent } from "../../../../../com/mui/events/DragEvent";
import { DataEvent } from "../../../events/DataEvent";
import { MsgManager } from "../../../manager/MsgManager";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { RolePlayer } from "../../../scene/player/entity/RolePlayer";
import { SPoint } from "../../../../../Message/Public/SPoint";
import { ThingUtil } from "../../../scene/layer/utils/ThingUtil";
import { SPlayerItem } from "../../../../../Message/Public/SPlayerItem";
import { ItemData } from "../../../resource/info/ItemData";
import { SkillConfig } from "../../../resource/SkillConfig";
import { SkillInfo } from "../../../model/SkillInfo";
import { SCrossSecretSkillInfo } from "../../../../../Message/Public/SCrossSecretSkillInfo";
import { GameClock } from "../../../../../com/gengine/ui/timer/GameClock";
import { CDItemData } from "../../../cache/CDItem/CDItemData";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class CurrentSkillPanel
    
    export  class CurrentSkillPanel extends GSprite
    {
        constructor()
        {
            super();
            this._itemAry = [];
            this._curSkillProps = [0, 0, 0];
            this._clockMap = new Map<any, any> /* flash.utils.Dictionary */();
            this.init();
            this._skillList = CopyConfig.instance.getCurCopySkillList(190);
            return;
        }

        public get isSkill(): Boolean
        {
            return this._isSkill;
        }

        public set ownPropNum(arg1: int)
        {
            this._ownPropNum = arg1;
            return;
        }

        /* internal  */init(): void
        {
            var loc5=null;
            var loc1=ObjCreate.createBitmap(ImagesConst.PackItemBg, 0, 0, this);
            var loc2=ObjCreate.createBitmap(ImagesConst.PackItemBg, 62, 0, this);
            var loc3=ObjCreate.createBitmap(ImagesConst.PackItemBg, 124, 0, this);
            var loc4=ObjCreate.createBitmap(ImagesConst.PropBg, 205, -15, this);
            var loc6=2;
            var loc7=2;
            var loc8=0;
            while (loc8 < 3) 
            {
                (loc5 = new BaseItem()).setSize(33, 33);
                loc5.move(loc6, loc7);
                loc6 = loc6 + 62;
                this._itemAry.push(loc5);
                loc5.addEventListener(flash.events.MouseEvent.CLICK, this.onBaseItemClickHandler);
                addChild(loc5);
                ++loc8;
            }
            this._shortcutsItem = new CopyShortcutsItem();
            this._shortcutsItem.move(208, -12);
            this._shortcutsItem.setSize(58, 58);
            this._shortcutsItem.setFreezingEffectPoint(32, 32);
            this._shortcutsItem.isShowBg = false;
            this._shortcutsItem.removeMouseOverOutListener();
            addChild(this._shortcutsItem);
            this._useSkillBtn = ObjCreate.createGButton(Language.getString(27615), 218, 40, 45, 20, this);
            this._useSkillBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onUseSkillBtnClickHandler);
            this._useSkillBtn.enabled = false;
            Dispatcher.addEventListener(EventName.UpgradeCrossSecretPropSelect, this.onCrossSecretPropSelectHandler);
            this.addEventListener(DragEvent.Event_Move_In, this.moveInHandler);
            return;
        }

        /* internal  */onBaseItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc1=arg1.currentTarget as BaseItem;
            if (loc1) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.UpgradeCrossSecretPropCancelSelect, loc1.itemData));
            }
            loc1.itemData = null;
            this._shortcutsItem.dragSource = null;
            var loc3=0;
            while (loc3 < this._itemAry.length) 
            {
                loc2 = this._itemAry[loc3] as BaseItem;
                if (loc2 == loc1) 
                {
                    this._curSkillProps[loc3] = 0;
                    break;
                }
                ++loc3;
            }
            this._useSkillBtn.enabled = false;
            this._itemCode = 0;
            this._isSkill = false;
            return;
        }

        /* internal  */onUseSkillBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            if (this._shortcutsItem.playingEffect) 
            {
                MsgManager.showRollTipsMsg(Language.getString(60054));
            }
            else if (this._shortcutsItem.dragSource) 
            {
                loc1 = GameMapUtil.getTilePoint(RolePlayer.instance.x, RolePlayer.instance.y);
                loc2 = new SPoint();
                loc3 = [];
                if (ThingUtil.selectEntity != null) 
                {
                    loc3 = [ThingUtil.selectEntity.entityInfo.entityInfo.entityId];
                }
                if (loc1 != null) 
                {
                    loc2.x = loc1.x;
                    loc2.y = loc1.y;
                }
                (loc4 = new Object()).itemCode = this._itemCode;
                loc4.entityIds = loc3;
                loc4.point = loc2;
                Dispatcher.dispatchEvent(new DataEvent(EventName.UpgradeCrossSecretUseSkill, loc4));
            }
            return;
        }

        /* internal  */onCrossSecretPropSelectHandler(arg1: DataEvent): void
        {
            if (this._ownPropNum < 6) 
            {
                return;
            }
            var loc1=arg1.data as SPlayerItem;
            Dispatcher.dispatchEvent(new DataEvent(EventName.UpgradeCrossSecretPropUseUpdate, loc1));
            var loc2=loc1.itemCode;
            this.updateItems(loc2);
            return;
        }

        /* internal  */moveInHandler(arg1: DragEvent): void
        {
            var loc1=arg1.dragItem as BaseItem;
            var loc2=arg1.dropItem as BaseItem;
            return;
        }

        /* internal  */updateItems(arg1: int): void
        {
            var loc3=null;
            var loc1=0;
            loc1 = 0;
            while (loc1 < this._curSkillProps.length) 
            {
                if (this._curSkillProps[loc1] == 0) 
                {
                    this._curSkillProps[loc1] = arg1;
                    break;
                }
                ++loc1;
            }
            var loc2=0;
            loc1 = 0;
            while (loc1 < this._curSkillProps.length) 
            {
                loc3 = this._itemAry[loc1] as BaseItem;
                if (this._curSkillProps[loc1] != 0) 
                {
                    loc3.itemData = new ItemData(this._curSkillProps[loc1]);
                    loc2 = loc2 + 1;
                }
                ++loc1;
            }
            if (loc2 == 3) 
            {
                this.updateSkillItemCode();
                this._isSkill = true;
            }
            return;
        }

        /* internal  */updateSkillItemCode(): void
        {
            var loc1=0;
            var loc2=null;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            this._shortcutsItem.dragSource = null;
            this._useSkillBtn.enabled = false;
            this._itemCode = 0;
            var loc3=this._skillList.length;
            var loc4=0;
            while (loc4 < loc3) 
            {
                loc2 = this._skillList[loc4];
                if (loc2.isSameCombination(this._curSkillProps)) 
                {
                    this._itemCode = loc2.itemCode;
                    break;
                }
                ++loc4;
            }
            if (this._itemCode != 0) 
            {
                if (loc5 = new ItemData(this._itemCode)) 
                {
                    if (loc6 = SkillConfig.instance.getInfoByName(loc5.effect)) 
                    {
                        (loc7 = new SkillInfo()).tSkill = loc6;
                        loc7.learned = true;
                        loc7.position = loc2.pos;
                        this._shortcutsItem.dragSource = loc7;
                        this._useSkillBtn.enabled = true;
                        this.updateCurSkillCd(false);
                    }
                }
            }
            return;
        }

        public resetSkill(): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < this._itemAry.length) 
            {
                loc1 = this._itemAry[loc2] as BaseItem;
                loc1.itemData = null;
                ++loc2;
            }
            this._curSkillProps = [0, 0, 0];
            this._shortcutsItem.dragSource = null;
            this._useSkillBtn.enabled = false;
            this._itemCode = 0;
            this._isSkill = false;
            return;
        }

        public updateSkillCd(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            this._skillCdInfos = arg1;
            var loc4=0;
            while (loc4 < this._skillCdInfos.length) 
            {
                loc2 = this._skillCdInfos[loc4] as SCrossSecretSkillInfo;
                loc1 = new ItemData(loc2.itemCode);
                loc3 = loc1.itemInfo.item.effect;
                if (this._clockMap[loc3] == null) 
                {
                    this._clockMap[loc3] = new GameClock();
                }
                (this._clockMap[loc3] as GameClock).time = loc2.nowDt;
                ++loc4;
            }
            this.updateCurSkillCd();
            return;
        }

        /* internal  */updateCurSkillCd(arg1: Boolean=true): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            if (this._skillCdInfos == null) 
            {
                return;
            }
            var loc7=0;
            while (loc7 < this._skillCdInfos.length) 
            {
                if ((loc5 = this._skillCdInfos[loc7] as SCrossSecretSkillInfo) && loc5.itemCode == this._itemCode) 
                {
                    loc1 = new CDItemData();
                    loc1.totalTime = 1000;
                    loc2 = this._shortcutsItem.dragSource as SkillInfo;
                    if (loc2) 
                    {
                        loc6 = this._clockMap[loc2.skillId];
                        if (arg1) 
                        {
                            loc4 = loc5.nowDt;
                        }
                        else 
                        {
                            loc4 = loc6.nowDate;
                        }
                        if ((loc3 = loc5.cooldownDt) && loc3.time > loc4.time) 
                        {
                            loc1.totalTime = loc3.time - loc4.time;
                        }
                    }
                    this._shortcutsItem.doCoolDown(loc1, true);
                }
                ++loc7;
            }
            return;
        }

        /* internal */ /* var */_itemAry: Array<any>;

        /* internal */ /* var */_shortcutsItem: CopyShortcutsItem;

        /* internal */ /* var */_useSkillBtn: GButton;

        /* internal */ /* var */_skillList: Array<any>;

        /* internal */ /* var */_curSkillProps: Array<any>;

        /* internal */ /* var */_itemCode: int;

        /* internal */ /* var */_isSkill: Boolean=false;

        /* internal */ /* var */_ownPropNum: int=0;

        /* internal */ /* var */_skillCdInfos: Array<any>;

        /* internal */ /* var */_clockMap: Map<any, any> /* flash.utils.Dictionary */;
    }
